home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 41
/
Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso
/
Aminet
/
comm
/
misc
/
MPackMUI.lha
/
MPackMUI
/
Source
/
MPack.C
< prev
next >
Wrap
C/C++ Source or Header
|
2000-07-27
|
22KB
|
833 lines
// --------------------------------------------------------------------------------------------------------------
//
// MPackMUI V1.01 MPack Module
//
// --------------------------------------------------------------------------------------------------------------
#include "MPack.h"
// --------------------------------------------------------------------------------------------------------------
void Encode2File()
{
BPTR tempfile;
char commandline[512], tempcommand[256];
LONG returncode, mimetype, *inputfile, *outputfile, *descfile, *subject, *state, *maxsize;
struct FileInfoBlock *fib;
// Encode a file to a file
// Send window to sleep
set(Windows[WID_MAIN], MUIA_Window_Sleep, TRUE);
// Get the input file, output file and subject
get(Gadgets[GID_INPUT_STRING_P1], MUIA_String_Contents, &inputfile);
get(Gadgets[GID_OUTPUT_STRING_P1], MUIA_String_Contents, &outputfile);
get(Gadgets[GID_SUBJECT_STRING_P1], MUIA_String_Contents, &subject);
// Check if MPack is in C:
if (!(tempfile = Lock("c:mpack", ACCESS_READ)))
{
DoEasyReq("Couldn't find MPack");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
UnLock(tempfile);
// Check if we can open the input file
if (!(tempfile = Lock((char *)inputfile, ACCESS_READ)))
{
DoEasyReq("Couldn't open input file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
// Allocate FileInfoBlock (freed later)
if (!(fib = AllocDosObjectTags(DOS_FIB, TAG_DONE)))
{
DoEasyReq("Couldn't allocate FileInfoBlock");
UnLock(tempfile);
CleanUp();
} /* if */
Examine(tempfile, fib);
if (fib->fib_DirEntryType > 0)
{
DoEasyReq("Couldn't open input file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
// Check if we can open the output file
if (tempfile = Lock((char *)outputfile, ACCESS_READ))
{
Examine(tempfile, fib);
if (fib->fib_DirEntryType > 0)
{
DoEasyReq("Couldn't open output file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
} /* if */
// Check if a description file is present
get(Gadgets[GID_DESC_STRING_P1], MUIA_Disabled, &state);
if (!(state))
{
// Check if we can open the description file
get(Gadgets[GID_DESC_STRING_P1], MUIA_String_Contents, &descfile);
if (!(tempfile = Lock((char *)descfile, ACCESS_READ)))
{
DoEasyReq("Couldn't open description file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
return;
} /* if */
Examine(tempfile, fib);
if (fib->fib_DirEntryType > 0)
{
DoEasyReq("Couldn't open description file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
} /* if */
// Free the FileInfoBlock
FreeDosObject(DOS_FIB, fib);
// Now construct the command line
sprintf(commandline, "mpack -o \"%s\" -s \"%s\" ", outputfile, subject);
// If there is a description file, add it to the command line
if (!(state))
{
sprintf(tempcommand, "-d \"%s\" ", descfile);
strcat(commandline, tempcommand);
} /* if */
// If there is a maximum size, add it to the command line
get(Gadgets[GID_MAX_STRING_P1], MUIA_Disabled, &state);
if (!(state))
{
get(Gadgets[GID_MAX_STRING_P1], MUIA_String_Integer, &maxsize);
sprintf(tempcommand, "-m %ld ", maxsize);
strcat(commandline, tempcommand);
} /* if */
// Add the content type to the command line
get(Gadgets[GID_TYPE_CYCLE_P1], MUIA_Cycle_Active, &mimetype);
sprintf(tempcommand, "-c \"%s\" ", MIMETypes[mimetype]);
strcat(commandline, tempcommand);
// Add the input file to the command line
sprintf(tempcommand, "\"%s\"", inputfile);
strcat(commandline, tempcommand);
// Set gauge to on
set(Gadgets[GID_PROGRESS_GAUGE_P1], MUIA_Gauge_InfoText, "Encoding file");
set(Gadgets[GID_PROGRESS_GAUGE_P1], MUIA_Gauge_Current, 1);
// And execute the whole commandline
if ((returncode = SystemTags(commandline, TAG_DONE)) == RETURN_ERROR)
{
DoEasyReq("Couldn't find MPack");
} /* if */
// Set gauge to off
set(Gadgets[GID_PROGRESS_GAUGE_P1], MUIA_Gauge_Current, 0);
set(Gadgets[GID_PROGRESS_GAUGE_P1], MUIA_Gauge_InfoText, "");
// Wake up window
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
} /* Encode2File() */
// --------------------------------------------------------------------------------------------------------------
void Decode2File()
{
BPTR tempfile;
char commandline[512], tempcommand[256], inputbase[256], testfilename[256], gaugetext[256];
LONG returncode, *inputfile, *outputdir, *state1, *state2;
struct FileInfoBlock *fib;
UBYTE numfiles, pos, loop;
// Decode a file to a file
// Send window to sleep
set(Windows[WID_MAIN], MUIA_Window_Sleep, TRUE);
// Get the input file and output directory
get(Gadgets[GID_INPUT_STRING_P2], MUIA_String_Contents, &inputfile);
get(Gadgets[GID_OUTPUT_STRING_P2], MUIA_String_Contents, &outputdir);
// Check if Munpack is in C:
if (!(tempfile = Lock("c:munpack", ACCESS_READ)))
{
DoEasyReq("Couldn't find Munpack");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
UnLock(tempfile);
// Check if we can open the input file
if (!(tempfile = Lock((char *)inputfile, ACCESS_READ)))
{
DoEasyReq("Couldn't open input file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
// Allocate FileInfoBlock (freed later)
if (!(fib = AllocDosObjectTags(DOS_FIB, TAG_DONE)))
{
DoEasyReq("Couldn't allocate FileInfoBlock");
UnLock(tempfile);
CleanUp();
} /* if */
Examine(tempfile, fib);
if (fib->fib_DirEntryType > 0)
{
DoEasyReq("Couldn't open input file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
// Check if the output directory is OK
if (!(tempfile = Lock((char *)outputdir, ACCESS_READ)))
{
DoEasyReq("Invalid output directory");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
return;
} /* if */
Examine(tempfile, fib);
if (fib->fib_DirEntryType < 0)
{
DoEasyReq("Invalid output directory");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
// Check for Force and Unpack
get(Gadgets[GID_FORCE_CHECK_P2], MUIA_Selected, &state1);
get(Gadgets[GID_UNPACK_CHECK_P2], MUIA_Selected, &state2);
// Check how many files there are
pos = strlen((char *)inputfile);
while (pos != 0 && ((char *)inputfile)[pos] != '.')
{
pos--;
} /* while */
if (pos == 0 || isdigit(((char *)inputfile)[pos + 1]) == 0)
{
// Only one file, so just decode it and exit
// Set gauge to on
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_Current, 1);
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_Max, 1);
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_InfoText, "Decoding file 1 / 1");
sprintf(commandline, "munpack >NIL: <NIL: -C \"%s\" -q ", outputdir);
if (state1)
{
strcat(commandline, "-f ");
} /* if */
if (state2)
{
strcat(commandline, "-t ");
} /* if */
sprintf(tempcommand, "\"%s\"", inputfile);
strcat(commandline, tempcommand);
if ((returncode = SystemTags(commandline, TAG_DONE)) == RETURN_ERROR)
{
DoEasyReq("Couldn't find Munpack");
} /* if */
// Reset gauge to off
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_Current, 0);
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_InfoText, "");
// Wake up window
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
// Multi-part files found, find how many
// Get base of name, e.g. for file Packed.01, base is Packed
strncpy(inputbase, (char *)inputfile, pos);
inputbase[pos] = '\0';
numfiles = 1;
loop = TRUE;
while (loop == TRUE)
{
if (numfiles < 10)
{
sprintf(testfilename, "%s.0%ld", inputbase, numfiles);
} /* if */
else
{
sprintf(testfilename, "%s.%ld", inputbase, numfiles);
} /* else */
if (!(tempfile = Lock(testfilename, ACCESS_READ)))
{
loop = FALSE;
} /* if */
else
{
UnLock(tempfile);
numfiles++;
} /* else */
} /* while */
numfiles--;
// Now we have a base name and the number of files. Let's decode them all
// Set gauge to on
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_Max, numfiles);
sprintf(gaugetext, "Decoding file %%ld / %ld", numfiles);
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_InfoText, gaugetext);
for (loop = 1; loop < numfiles + 1; loop++)
{
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_Current, loop);
if (loop < 10)
{
sprintf(testfilename, "%s.0%ld", inputbase, loop);
} /* if */
else
{
sprintf(testfilename, "%s.%ld", inputbase, loop);
} /* else */
sprintf(commandline, "munpack >NIL: <NIL: -C \"%s\" -q ", (char *)outputdir);
if (state1)
{
strcat(commandline, "-f ");
} /* if */
if (state2)
{
strcat(commandline, "-t ");
} /* if */
sprintf(tempcommand, "\"%s\"", testfilename);
strcat(commandline, tempcommand);
if ((returncode = SystemTags(commandline, TAG_DONE)) == RETURN_ERROR)
{
DoEasyReq("Couldn't find Munpack");
} /* if */
} /* for */
// Reset gauge to off
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_InfoText, "");
set(Gadgets[GID_PROGRESS_GAUGE_P2], MUIA_Gauge_Current, 0);
// Wake up window
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
} /* Decode2File() */
// --------------------------------------------------------------------------------------------------------------
void Encode2Mail()
{
BPTR tempfile;
char commandline[512], tempcommand[256], sendmailprog[256], tempsendmailprog[256], message[256];
LONG returncode, mimetype, *inputfile, *address, *subject, *state, *descfile, *maxsize;
struct FileInfoBlock *fib;
// Encode a file and send by E-Mail
// Send window to sleep
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
// Get the input file, address(es) and subject
get(Gadgets[GID_INPUT_STRING_P3], MUIA_String_Contents, &inputfile);
get(Gadgets[GID_ADDRESS_STRING_P3], MUIA_String_Contents, &address);
get(Gadgets[GID_SUBJECT_STRING_P3], MUIA_String_Contents, &subject);
// Check if MPack is in C:
if (!(tempfile = Lock("c:mpack", ACCESS_READ)))
{
DoEasyReq("Couldn't find MPack");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
UnLock(tempfile);
// Attempt to locate file used to send mail (stored in variable SENDMAIL)
if ((GetVar("SENDMAIL", sendmailprog, 256, NULL)) == -1)
{
strcpy(sendmailprog, "sendmail");
} /* if */
sprintf(tempsendmailprog, "c:%s", sendmailprog);
// Check if Sendmail is in C:
if (!(tempfile = Lock(tempsendmailprog, ACCESS_READ)))
{
sprintf(message, "Couldn't find %s", sendmailprog);
DoEasyReq(message);
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
UnLock(tempfile);
// Check if we can open the input file
if (!(tempfile = Lock((char *)inputfile, ACCESS_READ)))
{
DoEasyReq("Couldn't open input file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
// Allocate FileInfoBlock (freed later)
if (!(fib = AllocDosObjectTags(DOS_FIB, TAG_DONE)))
{
DoEasyReq("Couldn't allocate FileInfoBlock");
UnLock(tempfile);
CleanUp();
} /* if */
Examine(tempfile, fib);
if (fib->fib_DirEntryType > 0)
{
DoEasyReq("Couldn't open input file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
// Check we have an address
if (((char *)address)[0] == '\0')
{
DoEasyReq("No address(es) specified");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
return;
} /* if */
// Check if a description file is present
get(Gadgets[GID_DESC_STRING_P3], MUIA_Disabled, &state);
if (!(state))
{
// Check if we can open the description file
get(Gadgets[GID_DESC_STRING_P3], MUIA_String_Contents, &descfile);
if (!(tempfile = Lock((char *)descfile, ACCESS_READ)))
{
DoEasyReq("Couldn't open description file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
return;
} /* if */
Examine(tempfile, fib);
if (fib->fib_DirEntryType > 0)
{
DoEasyReq("Couldn't open description file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
} /* if */
// Free the FileInfoBlock
FreeDosObject(DOS_FIB, fib);
// Now construct the command line
sprintf(commandline, "mpack -s \"%s\" ", subject);
// If there is a description file, add it to the command line
if (!(state))
{
sprintf(tempcommand, "-d \"%s\" ", descfile);
strcat(commandline, tempcommand);
} /* if */
// If there is a maximum size, add it to the command line
get(Gadgets[GID_MAX_STRING_P3], MUIA_Disabled, &state);
if (!(state))
{
get(Gadgets[GID_MAX_STRING_P3], MUIA_String_Integer, &maxsize);
sprintf(tempcommand, "-m %ld ", maxsize);
strcat(commandline, tempcommand);
} /* if */
// Add the content type to the command line
get(Gadgets[GID_TYPE_CYCLE_P3], MUIA_Cycle_Active, &mimetype);
sprintf(tempcommand, "-c \"%s\" ", MIMETypes[mimetype]);
strcat(commandline, tempcommand);
// Add the input file and the address to the command line
sprintf(tempcommand, "\"%s\" ", inputfile);
strcat(commandline, tempcommand);
strcat(commandline, (char *)address);
// Set gauge to on
set(Gadgets[GID_PROGRESS_GAUGE_P3], MUIA_Gauge_InfoText, "Encoding file");
set(Gadgets[GID_PROGRESS_GAUGE_P3], MUIA_Gauge_Current, 1);
// And execute the whole commandline
if ((returncode = SystemTags(commandline, TAG_DONE)) == RETURN_ERROR)
{
DoEasyReq("Couldn't find MPack");
} /* if */
// Set gauge to off
set(Gadgets[GID_PROGRESS_GAUGE_P3], MUIA_Gauge_Current, 0);
set(Gadgets[GID_PROGRESS_GAUGE_P3], MUIA_Gauge_InfoText, "");
// Wake up window
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* Encode2Mail() */
// --------------------------------------------------------------------------------------------------------------
void Encode2NG()
{
BPTR tempfile;
char commandline[512], tempcommand[256], postnewsprog[256], temppostnewsprog[256], message[256];
LONG returncode, mimetype, *inputfile, *newsgroup, *subject, *state, *descfile, *maxsize;
struct FileInfoBlock *fib;
// Encode a file and post to a newsgroup
// Send window to sleep
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
// Get the input file, newsgroup(s) and subject
get(Gadgets[GID_INPUT_STRING_P4], MUIA_String_Contents, &inputfile);
get(Gadgets[GID_NEWSGROUP_STRING_P4], MUIA_String_Contents, &newsgroup);
get(Gadgets[GID_SUBJECT_STRING_P4], MUIA_String_Contents, &subject);
// Check if MPack is in C:
if (!(tempfile = Lock("c:mpack", ACCESS_READ)))
{
DoEasyReq("Couldn't find MPack");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
UnLock(tempfile);
// Attempt to locate file used to post news (stored in variable POSTNEWS)
if ((GetVar("POSTNEWS", postnewsprog, 256, NULL)) == -1)
{
strcpy(postnewsprog, "postnews");
} /* if */
sprintf(temppostnewsprog, "c:%s", postnewsprog);
// Check if Sendmail is in C:
if (!(tempfile = Lock(temppostnewsprog, ACCESS_READ)))
{
sprintf(message, "Couldn't find %s", postnewsprog);
DoEasyReq(message);
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
UnLock(tempfile);
// Check if we can open the input file
if (!(tempfile = Lock((char *)inputfile, ACCESS_READ)))
{
DoEasyReq("Couldn't open input file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* if */
// Allocate FileInfoBlock (freed later)
if (!(fib = AllocDosObjectTags(DOS_FIB, TAG_DONE)))
{
DoEasyReq("Couldn't allocate FileInfoBlock");
UnLock(tempfile);
CleanUp();
} /* if */
Examine(tempfile, fib);
if (fib->fib_DirEntryType > 0)
{
DoEasyReq("Couldn't open input file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
// Check we have an address
if (((char *)newsgroup)[0] == '\0')
{
DoEasyReq("No newsgroup(s) specified");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
return;
} /* if */
// Check if a description file is present
get(Gadgets[GID_DESC_STRING_P4], MUIA_Disabled, &state);
if (!(state))
{
// Check if we can open the description file
get(Gadgets[GID_DESC_STRING_P4], MUIA_String_Contents, &descfile);
if (!(tempfile = Lock((char *)descfile, ACCESS_READ)))
{
DoEasyReq("Couldn't open description file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
return;
} /* if */
Examine(tempfile, fib);
if (fib->fib_DirEntryType > 0)
{
DoEasyReq("Couldn't open description file");
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
FreeDosObject(DOS_FIB, fib);
UnLock(tempfile);
return;
} /* if */
UnLock(tempfile);
} /* if */
// Free the FileInfoBlock
FreeDosObject(DOS_FIB, fib);
// Now construct the command line
sprintf(commandline, "mpack -s \"%s\" ", subject);
// If there is a description file, add it to the command line
if (!(state))
{
sprintf(tempcommand, "-d \"%s\" ", descfile);
strcat(commandline, tempcommand);
} /* if */
// If there is a maximum size, add it to the command line
get(Gadgets[GID_MAX_STRING_P4], MUIA_Disabled, &state);
if (!(state))
{
get(Gadgets[GID_MAX_STRING_P4], MUIA_String_Integer, &maxsize);
sprintf(tempcommand, "-m %ld ", maxsize);
strcat(commandline, tempcommand);
} /* if */
// Add the content type to the command line
get(Gadgets[GID_TYPE_CYCLE_P4], MUIA_Cycle_Active, &mimetype);
sprintf(tempcommand, "-c \"%s\" ", MIMETypes[mimetype]);
strcat(commandline, tempcommand);
// Add the input file and the address to the command line
sprintf(tempcommand, "\"%s\" ", inputfile);
strcat(commandline, tempcommand);
sprintf(tempcommand, "-n %s", newsgroup);
strcat(commandline, tempcommand);
// Set gauge to on
set(Gadgets[GID_PROGRESS_GAUGE_P4], MUIA_Gauge_InfoText, "Encoding file");
set(Gadgets[GID_PROGRESS_GAUGE_P4], MUIA_Gauge_Current, 1);
// And execute the whole commandline
if ((returncode = SystemTags(commandline, TAG_DONE)) == RETURN_ERROR)
{
DoEasyReq("Couldn't find MPack");
} /* if */
// Set gauge to off
set(Gadgets[GID_PROGRESS_GAUGE_P4], MUIA_Gauge_Current, 0);
set(Gadgets[GID_PROGRESS_GAUGE_P4], MUIA_Gauge_InfoText, "");
// Wake up window
set(Windows[WID_MAIN], MUIA_Window_Sleep, FALSE);
return;
} /* Encode2NG() */
// --------------------------------------------------------------------------------------------------------------
// End Of Text